package may.test_5_6;

import java.util.ArrayList;
import java.util.Map;

public class Solution {
    public ArrayList<ArrayList<Integer>> setZeroes (ArrayList<ArrayList<Integer>> matrix) {
        // write code here
        ArrayList<Integer> arri = new ArrayList<>();
        ArrayList<Integer> arrj = new ArrayList<>();
        for (int i = 0; i < matrix.size(); i++) {
            int cout = 1;
            for(int j = 0; j < matrix.get(i).size(); j++) {
                cout *= matrix.get(i).get(j);
            }
            if(cout == 0) {
                arri.add(i);
            }
        }
        for (int j = 0; j < matrix.get(0).size(); j++) {
            int count = 1;
            for (int i = 0; i < matrix.size(); i++) {
                count *= matrix.get(i).get(j);
            }
            if(count == 0) {
                arrj.add(j);
            }
        }
        for (int i = 0; i < arri.size(); i++) {
            int tmp = arri.get(i);
            ArrayList<Integer> arr = new ArrayList<>();
            for (int  j = 0; j < matrix.get(tmp).size(); i++) {
                arr.add(0);
            }
            matrix.set(tmp,arr);
        }
        for (int j = 0; j < arrj.size(); j++) {
            int tmp = arrj.get(j);
            for (int i = 0; i < matrix.size(); i++) {
                ArrayList<Integer> arr = matrix.get(i);
                arr.set(tmp,0);
                matrix.set(i,arr);
            }
        }
        return matrix;
    }
    public int maxWine (int[] weights) {
       int n = weights.length;
       return Math.min(weights[0] + rob(weights,2,n - 2),rob(weights,1,n -1));
    }
    private int rob(int[] nums,int left,int right) {
       if (left > right) {
           return 0;
       }
       int n = nums.length;
       int[] f = new int[n];
       int[] g = new int[n];
       f[left] = nums[left];
       for (int i = left + 1; i <= right; i++) {
           f[i] = g[i - 1] + nums[i];
           g[i] = Math.max(g[i - 1],f[i - 1]);
       }
       return Math.max(f[right],g[right]);
    }
}
